/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#include "log.h"
#include "dxindexbuffer.h"

namespace Engine
{
	/**********************************************************************************************************/
	DXIndexBuffer::DXIndexBuffer(IDirect3DIndexBuffer9* indexBuffer)
		:m_indexBuffer(indexBuffer)
	{
	}
	/**********************************************************************************************************/
	DXIndexBuffer::~DXIndexBuffer()
	{
		Log::GetSingleton() << "DXIndexBuffer deleted" << std::endl;
	}
	/**********************************************************************************************************/
	void* DXIndexBuffer::Lock()
	{
		void *pData = 0;
		if(FAILED(m_indexBuffer->Lock(0,0,&pData,0)))
			throw std::logic_error("Can't lock dx index buffer");
		return pData;
	}
	/**********************************************************************************************************/
	const void* DXIndexBuffer::Lock()const
	{
		void *pData = 0;
		if(FAILED(m_indexBuffer->Lock(0,0,&pData,0)))
			throw std::logic_error("Can't lock dx index buffer");
		return pData;
	}	/**********************************************************************************************************/
	void DXIndexBuffer::UnLock()const
	{
		if(FAILED(m_indexBuffer->Unlock()))
			throw std::logic_error("Can't unlock dx index buffer");
	}
	/**********************************************************************************************************/
	IDirect3DIndexBuffer9* DXIndexBuffer::GetBuffer()
	{
		return m_indexBuffer.GetPointer();
	}
	/**********************************************************************************************************/
}
